-
Notifications
You must be signed in to change notification settings - Fork 35
Remove 3-argument {_,}evaluate!!
; clean up submodel code
#960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
_evaluate!!
; clean up submodel code{_,}evaluate!!
; clean up submodel code
3dc22f4
to
4bb2526
Compare
Benchmark Report for Commit aaf0bc6Computer Information
Benchmark Results
|
4bb2526
to
55f838f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## breaking #960 +/- ##
============================================
- Coverage 82.85% 82.77% -0.09%
============================================
Files 38 38
Lines 4031 4011 -20
============================================
- Hits 3340 3320 -20
Misses 691 691 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dcd5c9d
to
31b0caa
Compare
DynamicPPL.jl documentation for PR #960 is available at: |
31b0caa
to
039a523
Compare
039a523
to
bfa48b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me, just had a few questions to check/inform myself.
function AbstractPPL.evaluate!!( | ||
model::Model, varinfo::AbstractVarInfo, context::AbstractContext | ||
) | ||
Base.depwarn( | ||
"The `context` argument to evaluate!!(model, varinfo, context) is deprecated.", | ||
:dynamicppl_evaluate_context, | ||
) | ||
new_ctx = combine_model_and_external_contexts(model.context, context) | ||
model = contextualize(model, new_ctx) | ||
return evaluate!!(model, varinfo) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't this deprecation added just a few weeks ago? Or am I mixing this with something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above; but I don't know, I might be open to leaving a helpful error message in (i.e., maybe it shouldn't continue behaving as it does, but it should throw an error message that guides people towards the right answer)? I do know that upstream packages use evaluate!! even though it is internal, pretty sure I've seen it in Pigeons.jl for example, and Turing itself obviously uses evaluate!! quite a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A manually crafted, more informative error message sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an error hint in src/DynamicPPL.jl
, so now this happens:
julia> using DynamicPPL, Distributions
julia> @model f() = x ~ Normal()
f (generic function with 2 methods)
julia> m = f(); v = VarInfo(m); c = DefaultContext()
DefaultContext()
julia> DynamicPPL.evaluate!!(m, v, c)
ERROR: MethodError: no method matching evaluate!!(::Model{…}, ::VarInfo{…}, ::DefaultContext)
The function `evaluate!!` exists, but no method is defined for this combination of argument types.
The method `evaluate!!(model, varinfo, new_ctx)` has been removed. Instead, you should store the `new_ctx` in the `model.context` field using `new_model = contextualize(model, new_ctx)`, and then call `evaluate!!(new_model, varinfo)` on the new model. (Note that, if the model already contained a non-default context, you will need to wrap the existing context.)
Closest candidates are:
evaluate!!(::Model, ::AbstractVarInfo)
@ DynamicPPL ~/ppl/dppl/src/model.jl:868
Stacktrace:
[1] top-level scope
@ REPL[10]:1
Some type information was truncated. Use `show(err)` to see complete types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @penelopeysm! I didn't know about adding error hints, that's neat.
This PR:
evaluate!!(model, varinfo, context)
in the DynamicPPL codebase_evaluate!!(model, varinfo, context)
as this method was only being used for submodelsIn return, it introduces:
_evaluate!!(submodel, varinfo, context, left)
. Yes, yes, I basically moved the implementation from one place to the other; but the whole point is that this was special-case behaviour that was only needed for submodels, so this at least makes it clearer.It also removes a lot of wrapper code for submodels. For example, we don't have this
ReturnedModelWrapper
andSampleable
thing any more, instead, there's justSubmodel
which wraps a model.I personally don't see the need for more than one layer of indirection for submodels (in terms of the data structure, the only difference between a submodel and a model is that the submodel carries information about whether it should be auto-prefixed). I had mucked around with this before in #815 and I didn't find any real problems with removing the wrappers there (in fact in that PR I went one step further and removed all wrappers, but that would have made it impossible to opt-out of prefixing and that's Bad(TM)).
I didn't add any new tests, but
test/submodel.jl
already contains quite extensive tests to make sure that everything behaves and it passes these tests so I'm quite happy.#959 needs to be merged first.Done.Follow-up from #952
Closes #720 (for good)